London | 26-ITP-May | Russom Gebremeskel | Sprint 2 | Coursework/sprint 2#1458
London | 26-ITP-May | Russom Gebremeskel | Sprint 2 | Coursework/sprint 2#1458russom-g wants to merge 15 commits into
Conversation
…t different stages.
…function needs fixing.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // The return value of pad when it is called for the first time is 00. this is because the value of num is 0 and the pad function adds a 0 to the front of the string until the num characters has at least 2 characters. | ||
|
|
There was a problem hiding this comment.
To be precise, what exactly is the return value of pad? I think you know what it is, but 00 doesn't quite exactly describe it
There was a problem hiding this comment.
Hi Liam. Thanks for reviewing my code.
The exact return value is 0 . It ads a single 0 instead of two 0s.
There was a problem hiding this comment.
Not quite - what data type is the return value of pad?
|
|
||
| // The return value of pad when it is called for the last time is 01. This is because the pad function adds a 0 to the front of the string if the characters of the string are less than 2. No newline at end of file |
| //The sum of 10 and 32 is undefined | ||
|
|
||
| // The above error message is displayed when tested with node. | ||
| // The cause of the error message is the semicolon that is placed after the return statement. |
There was a problem hiding this comment.
Did this actually cause an error message to be displayed?
There was a problem hiding this comment.
It returns '' The sum of 10 and 32 is undefined". Initially I had assumed that this was happening because of the semicolon after return. Now I run the code again this time without the semicolon still get "undefined" message. I did some research online and it is actually not just because of the semicolon but because both the return statement and the expression "a+b" are not on the same line.
There was a problem hiding this comment.
That's correct, and the point I want to make is that
It returns '' The sum of 10 and 32 is undefined".
Highlights that there was no "error message" such as a SyntaxError or TypeError, but rather there was a bug in the code, i.e. the code would run but wouldn't perform the correct operations. A subtle difference but a useful one!
| // 1) The above output (3) is displayed because the variable num is declared as a constant | ||
| // 2) .slice(-1) is used to get the last digit of num inside the function. | ||
| // 3) The function does not take any parameters so when it is called with an arguments it always returns the last digit of the constant num 103. | ||
|
|
There was a problem hiding this comment.
Would this be different if the variable was declared with let?
There was a problem hiding this comment.
No. I realise that the error is actually not because it declared as const. num isn't defined as the function's parameter so the function can take arguments later on when it's called.
There was a problem hiding this comment.
Great! You should amend the explanation so it is correct 🙂
…d added in order to test case for 1:00am to work
Learners, PR Template
Self checklist
Changelist
I manage to predict, find, interpret and fix the errors in programs. I debugged each files and corrected the programs. I implemented functions based on requirements. I interpreted programs using documentations.